//
// Selection Sort
// Created by Win10 on 2023/4/7.
//

#ifndef C_DATA_STRUCTURE_SELECTION_SORT_H
#define C_DATA_STRUCTURE_SELECTION_SORT_H


#include <algorithm>

template<typename T>
//整数或浮点数皆可使用
void selection_sort(T a[], int len) {
  for (int i = 0; i < len; i++) {
    int x = i;
    for (int j = i + 1; j < len; j++)
      if (a[x] > a[j]) x = j;
    if (i != x) std::swap(a[x], a[i]);
  }
}

#endif //C_DATA_STRUCTURE_SELECTION_SORT_H
